package com.blb.zy_community.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blb.zy_community.entity.ResponseResult;
import com.blb.zy_community.entity.ZyOwner;
import com.blb.zy_community.service.IZyOwnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 业主  前端控制器
 * </p>
 *
 * @author 二组
 * @since 2023-06-18
 */
@CrossOrigin
@RestController
public class ZyOwnerController {

    @Autowired
    private IZyOwnerService ownerService;

    @GetMapping("/owner/page")
    public ResponseResult<Page<ZyOwner>> getZyOwnerPage(
            @RequestParam(required = false, defaultValue = "1") Long current,
            @RequestParam(required = false, defaultValue = "5") Long size,
            @RequestParam(required = false ) String ownerNiceName,
            @RequestParam(required = false) String ownerRealName,
            @RequestParam(required = false) String ownerIdCard,
            @RequestParam(required = false) String ownerPhoneNumber
    ) {

        Page<ZyOwner> zyOwnerPage = ownerService.getZyOwnerPage(current, size, ownerNiceName, ownerRealName, ownerIdCard, ownerPhoneNumber);

        return ResponseResult.ok(zyOwnerPage);

    }
    @RequestMapping("/ownerName")
    public ResponseResult<String> getZyOwnerName(@RequestParam(required = false,defaultValue = "") String ownerRealName){
        List<ZyOwner> zyOwnerName = ownerService.getZyOwnerName(ownerRealName);
        return ResponseResult.ok(zyOwnerName);
    }

    /**
     * 注册用户
     * @param zyOwner
     * @return
     */
    @PostMapping("owner")
    public ResponseResult<String> addOwner(@RequestBody ZyOwner zyOwner){
        ownerService.save(zyOwner);
        return ResponseResult.ok(zyOwner);
    }

}
